const htmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');

function resolve(relPath) {//解析路径
    return path.resolve(__dirname, relPath);
}
module.exports = {
    entry:{                             //打包入口文件
        main: path.resolve('./src/script/main.js'),
        more: path.resolve('./src/script/more.js')
    },       
    output:{    
        path:path.resolve(__dirname + '/dist'),    //打包后的文件路径
        filename:'js/[name].js'            //打包后的文件名
    },
    devtool: 'inline-source-map',
    devServer: {
        contentBase: './dist'
    },
    plugins:[
        new htmlWebpackPlugin({
            filename: 'index.html',
            //注意传的参数是一个对象
            template:'index.html',   //传一个模板，就是根目录下的index.html
            inject: true
        }),
        new CleanWebpackPlugin(['dist'])
    ],
    module:{
        rules: [{
            test: /\.js$/,
            use: 'babel-loader',
            include: [resolve('./src')]
        },{
            test: /\.vue$/,
            use: {
                loader: 'vue-loader',
                // options: utils.vueLoaderOptions()
            }
        },{
            test: /\.css$/,
            use: [
              'style-loader',
              'css-loader'
            ]
        }]
    }
}